home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / mail / mh / contrib / multimedia / mhweather.shar / mhnsend < prev    next >
Text File  |  1993-03-15  |  2KB  |  107 lines

  1. #!/usr/bin/perl
  2. #
  3. # mhnsend - run mhn non-interactively on the draft and then post the draft
  4. #
  5. # Author: Jerry Sweet <jns@fernwood.mpk.ca.us>
  6. #
  7. # $Id: mhnsend,v 1.3 1992/11/11 08:48:33 jsweet Exp $
  8.  
  9. #
  10. # Subprograms
  11. #
  12.  
  13.  
  14. sub barf {
  15.   print STDERR "$prog: ", @_, "\n";
  16.   exit 1;
  17. }
  18.  
  19. sub sh {
  20.   local($_) = @_;
  21.   local($st);
  22.  
  23.   if ($verbose) {
  24.     print "\t$_\n";
  25.   }
  26.  
  27.   return if $debug;
  28.  
  29.   $st = system "$_";
  30.  
  31.   if ($st >> 8) {
  32.     split;
  33.     &barf("$_[0] failed with status ", $st >> 8);
  34.   }
  35. }
  36.  
  37. sub read_profile {
  38.   # Defines associative array %PROFILE_COMPONENT indexed by lower case
  39.   # component name.  Continuation lines are tacked on.  New
  40.   # occurrences of a component wipe out previous occurrences of the
  41.   # same component, but probably shouldn't.
  42.  
  43.   local($profile) = defined $ENV{'MH'} ? $ENV{'MH'} : 
  44.                      $ENV{'HOME'} . "/.mh_profile";
  45.   local($profile_component) = 'x-bogus';
  46.   local($_);
  47.   
  48.   &barf("can't open profile \"$profile\" - $!")
  49.     unless open(PROFILE, "<$profile");
  50.  
  51.   while (<PROFILE>) {
  52.     /^(\S+):\s*/ && do {
  53.             ($profile_component = $1) =~ tr/A-Z/a-z/;
  54.             $PROFILE_COMPONENT{$profile_component} = $';
  55.         };
  56.   
  57.     /^[ \t]/ && do {
  58.             $PROFILE_COMPONENT{$profile_component} .= $_;
  59.         };
  60.   }
  61. }
  62.  
  63. #
  64. # Main program
  65. #
  66.  
  67. ($prog = $0) =~ s%.*/%%;
  68.  
  69. $editor = 'mhn';    # Default editor.
  70.  
  71. # Check the profile.
  72.  
  73. &read_profile;
  74. if (defined $PROFILE_COMPONENT{$prog}) {
  75.   push(@Args, split(' ', $PROFILE_COMPONENT{$prog}));
  76. }
  77.  
  78. # Check the command line arguments.
  79.  
  80. push(@Args, @ARGV);
  81.  
  82. while ($_ = shift @Args) {
  83.   /^-debug$/    && $debug++;
  84.   /^-editor$/   && ($editor = shift @Args);
  85.   /^-verbose$/    && $verbose++;
  86.   /^[^\-]/    && ($file = $_);
  87. }
  88.  
  89. if (! $file) {
  90.   if (defined $ENV{'mhdraft'}) {
  91.     $file = $ENV{'mhdraft'};
  92.   }
  93.   else {
  94.     &barf("no draft file specified");
  95.   }
  96. }
  97. else {
  98.   $ENV{'mhdraft'} = $file;
  99. }
  100.  
  101. &sh("$editor $file >/dev/null");
  102. &sh("send $file >/dev/null");
  103. print("\trm $file\n") if ($verbose || $debug);
  104. unlink($file) unless $debug;
  105. exit 0;
  106.  
  107.